<?php

class AlmacenesController extends AppController {

    public $helpers = array('Html', 'Form', 'Session', 'Js');
    public $uses = array('Almacene');
    public $layout = 'default';
    public $name = 'Almacenes';

 
    function index() {
	    $almacenes=$this->Almacene->find('all');
	    $this->set(compact('almacenes'));
    }

    function insertar() {
        
        if (!empty($this->data)):
          // debug($this->data);exit;
            $this->Almacene->create();

            if ($this->Almacene->save($this->data)) {

                $this->Session->setFlash('Espacio registrado!!!!!');
                $this->redirect(array('action' => 'index'), null, true);
            } else {
                $this->Session->setFlash('No se pudo registrar!!!');
            }


        endif;
    }

    function editar($id = null) {
        $this->Almacene->id = $id;
        
        if (!$id) {
            $this->Session->setFlash('No existe tal registro');
            $this->redirect(array('action' => 'index'), null, true);
        }
        if (empty($this->data)) {
            $this->data = $this->Almacene->read(); //find(array('id' => $id));

        } else {
            //debug($this->data);exit;
            if ($this->Almacene->save($this->data)) {
                $this->Session->setFlash('Los datos fueron modificados');
                $this->redirect(array('action' => 'index'), null, true);
            } else {
                $this->Session->setFlash('no se pudo modificar!!');
            }
        }
        $opt = array('1' => 'Alta', '0' => 'Baja');

        $this->set(compact('opt'));
    }

    function eliminar($id = null) {
        if (!$id) {
            $this->Session->setFlash('id Invalida para reclamo');
            $this->redirect(array('action' => 'index'), null, true);
        }
        if ($this->Almacene->delete($id)) {
            $this->Session->setFlash('El Cliente  ' . $id . ' fue borrado');
            $this->redirect(array('action' => 'index'), null, true);
        }
    }

    
    

}

?>